<script>

import SidebarNav from "@/components/SidebarNav.vue";
import DocFilters from "@/components/DocFilters.vue";
import {EvevtBus} from "@/utils/EvevtBus";
import Request from "@/api/request";
import {remove} from "@/api/docMG";

export default {
  name: "research",
  components: {DocFilters, SidebarNav},
  beforeCreate() {
    Request.get("/model/modules").then(res => {
      console.log(res)
      this.modules = res.data.filter(item => {
        return item.id === 27 || item.id === 26
      })
    })
  },
  mounted() {
    EvevtBus.$on('multipleSelection', (multipleSelection) => {
      let arr = []
      multipleSelection.forEach(item => {
        arr.push(item.id)
      })
      this.multipleSelection = arr
    })
  },
  data() {
    return {
      modules: [{}],
      multipleSelection: [],
      activeName: '0',
      title: {
        research: "横向课题",
        govresearch: "纵向课题",
      }
    }
  },
  computed: {
    lable: function () {
      return this.title[this.$route.name]
    }
  },
  methods: {
    remove() {
      remove(this.multipleSelection);
      this.query()
    },
    upload() {
      if (this.$router.currentRoute.name !== "recycled") {
        this.$router.push(this.$router.currentRoute.path + "upload", () => {
        }, (error) => {
          if (error) {
            // vue-router 3.1.0+ push/replace cause NavigationDuplicated error
            // https://github.com/ElemeFE/element/issues/17044
            if (error.name === 'NavigationDuplicated') return
            console.error(error)
          }
        });
      }
    }
  }
}
</script>

<template>
  <el-container>
    <el-aside class="aside">
      <SidebarNav :modules=modules></SidebarNav>
    </el-aside>
    <el-main class="main">
      <el-row>
        <el-tabs type="border-card" v-model="activeName">
          <el-tab-pane :label="lable" name="0">
            <!--            <DocFilters></DocFilters>-->
            <router-view v-if="activeName==='0'" :doc_status="activeName"></router-view>
          </el-tab-pane>
          <!--          <el-tab-pane label="草稿箱" name="1">-->
          <!--            <router-view v-if="activeName==='1'" :doc_status="activeName"></router-view>-->
          <!--          </el-tab-pane>-->
        </el-tabs>
        <div class="upload" v-if="this.$route.name!=='recycled'">
          <el-button @click="upload()" type="primary" size="small"><i class="iconfont icon-srcm-i-nav-upload"></i>上传
          </el-button>
          <!--          <el-dropdown trigger="click">-->
          <el-button type="danger" size="small" @click.native="remove">
            批量删除
          </el-button>
          <!--            <el-dropdown-menu>-->
          <!--              <el-dropdown-item>导出引文</el-dropdown-item>-->
          <!--              <el-dropdown-item>导出表格</el-dropdown-item>-->
          <!--              <el-dropdown-item @click.native="remove" class="batch-delete" :divided=true>批量删除</el-dropdown-item>-->
          <!--            </el-dropdown-menu>-->
          <!--          </el-dropdown>-->
        </div>
      </el-row>
    </el-main>
  </el-container>
</template>

<style scoped>
.batch-delete {
  color: #f56c6c;
}

/*.batch-delete:hover {
  background-color: #fbc4c4;
  color: white !important;
}*/

.aside {
  overflow: hidden;
  width: auto !important;
}

.main {
  padding: 0;
}

.export {
  margin-left: 10px;
}

.upload {
  position: absolute;
  right: 20px;
  top: 5px;
}

.export {
  margin-left: 10px;
}
</style>
